package com.yifeixi.validation.constraint;

import com.yifeixi.validation.entity.Car;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author YiFeiXi
 */
public class ValidPassengerCountValidator implements ConstraintValidator<ValidPassengerCount, Car> {

  @Override
  public boolean isValid(Car car, ConstraintValidatorContext context) {
    if (car == null) {
      return true;
    }

    return car.getPassengers() == null || car.getPassengers().size() <= car.getSeatCount();
  }

  @Override
  public void initialize(ValidPassengerCount constraintAnnotation) {
  }
}
